﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ECONTACT.Bussiness;
using ECONTACT.DataLayer;
using System.Data;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
using DevComponents.Editors.DateTimeAdv;

namespace ECONTACT.Controller
{
    public class PhuHuynhCtrl
    {
        PhuHuynhData m_PhuhuynhData = new PhuHuynhData();

        #region Hien thi ComboBox
        public void HienThiComboBox(ComboBoxEx comboBox)
        {
            comboBox.DataSource = m_PhuhuynhData.LayDsPhuHuynh();
            comboBox.DisplayMember = "MaPH";
            comboBox.ValueMember = "MaPH";
        }
        public void HienThiComboBoxTen(ComboBoxEx comboBox)
        {
            comboBox.DataSource = m_PhuhuynhData.LayDsPhuHuynh();
            comboBox.DisplayMember = "TenPH";
            comboBox.ValueMember = "MaPH";
        }
        #endregion

        #region Do du lieu vao DataGridView
        public void HienThi(DataGridView dGV, BindingNavigator bN)
        {
            BindingSource bS = new BindingSource();

            bS.DataSource = m_PhuhuynhData.LayDsPhuHuynh();
            bN.BindingSource = bS;
            dGV.DataSource = bS;
        }

        public void HienThi(DataGridViewX dGV,
                            TextBoxX txtMaPhuHuynh,
                            TextBoxX txtTenPH,
                            TextBoxX txtSDT,
                            DateTimeInput dtpNgaySinh,
                            TextBoxX txtDiaChi)
        {
            BindingSource bS = new BindingSource();
            bS.DataSource = m_PhuhuynhData.LayDsPhuHuynh();

            DataTable dT = m_PhuhuynhData.LayDsPhuHuynh();

            txtMaPhuHuynh.DataBindings.Clear();
            txtMaPhuHuynh.DataBindings.Add("Text", bS, "MaPH");

            txtTenPH.DataBindings.Clear();
            txtTenPH.DataBindings.Add("Text", bS, "TenPH");

            txtSDT.DataBindings.Clear();
            txtSDT.DataBindings.Add("Text", bS, "SDT");

            dtpNgaySinh.DataBindings.Clear();
            dtpNgaySinh.DataBindings.Add("Value", bS, "NgaySinh");

            txtDiaChi.DataBindings.Clear();
            txtDiaChi.DataBindings.Add("Text", bS, "DiaChi");
            //bN.BindingSource = bS;
            dGV.DataSource = bS;
        }
        #endregion

        //public void LuuPhuHuynh(String MaPH, String TenPH, String SDT, DateTime NgaySinh, String DiaChi)
        public String LuuPhuHuynh(String TenPH, String SDT, DateTime NgaySinh, String DiaChi)
        {
            return m_PhuhuynhData.LuuPhuHuynh(TenPH,SDT,NgaySinh,DiaChi);
        }

        public String UpdatePhuHuynh(String MaPH, String TenPH, String SDT, DateTime NgaySinh, String DiaChi)
        {
            return m_PhuhuynhData.UpdatePhuHuynh(MaPH, TenPH, SDT, NgaySinh, DiaChi);
        }

        public void DeletePhuHuynh(String MaPH)
        {
            m_PhuhuynhData.DeletePhuHuynh(MaPH);
        }
    }
}
